package com.ext.aic.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;

import com.ext.aic.box.enums.Packages;
import com.ext.aic.ui.BaseActivity;

public class RedirectUtils {
    private static volatile RedirectUtils instance;

    public static RedirectUtils getInstance() {
        if (instance == null) {
            synchronized (RedirectUtils.class) {
                if (instance == null) {
                    instance = new RedirectUtils();
                }
            }
        }
        return instance;
    }

    public <T extends BaseActivity> void startActivity(Context context, Class<T> clazz, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(context, clazz);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public <T extends BaseActivity> void startActivity(Context context, Class<T> clazz) {
        startActivity(context, clazz, new Bundle());
    }

    public void startWeChat(Context context) {
        PackageManager pm = context.getPackageManager();
        Intent launchIntent = pm.getLaunchIntentForPackage(Packages.WECHAT.getPackageName());
        if (launchIntent != null) {
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(launchIntent);
        } else {
            try {
                context.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=" + Packages.WECHAT.getPackageName())));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
